package ar.com.photo_admin.service.security

/**
 * Service to generate tokens. 
 */
class TokenGeneratorService {

	def springSecurityService
		
	/**
	 * Generates a token for the given arguments.
	 */
	def generateTokenOfList(List elements) {
		
		def randomGenerator = new Random(new Date().getTime())
		def token = randomGenerator.nextInt()
		
		elements.each { it -> 
			token += it.hashCode()
		}
		
		return springSecurityService.encodePassword(token.toString())		
	}
	
	/**
	 * Generates a token for the given argument.
	 */
	def generateToken(def element) {
		return generateTokenOfList([element])
	}
}
